package com.example.zhidao.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.zhidao.dao.BlogMapper;
import com.example.zhidao.dao.CommentsMapper;
import com.example.zhidao.model.po.Comments;
import com.example.zhidao.model.vo.CommentVo;
import com.example.zhidao.service.CommentsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import java.beans.Transient;
import java.util.List;

@Service
public class CommentsServiceImpl extends ServiceImpl<CommentsMapper, Comments> implements CommentsService {

    @Resource
    CommentsMapper commentsMapper;

    @Resource
    BlogMapper blogMapper;

//    该函数为增加评论后，博客评论数加一
//    开启事务同生共死 欸嘿
@Transactional(rollbackFor = Exception.class)
    @Override
    public int onecomment(Comments comments){
        int result=0;
        try{
         commentsMapper.insert(comments);
         int i=blogMapper.setcomm(comments.getBid());
            result = 1;
    } catch (Exception e) {
        // 回滚事务
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        result = 0;
    }
return result;
    }


}
